package com.summer.springboot.ch3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

/**
 * Created by thinkpad on 2018/7/8.
 */

@Service
public class ScheduledTaskService {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

    @Autowired
    private  AsyncTaskService asyncTaskService;


    @Scheduled(fixedRate = 5000)
    @Async
    public void reportCurrentTime(){
//        System.out.println("每隔五秒执行一次：" + sdf.format(new Date()));

        for (int i = 0; i < 10; i++) {
            asyncTaskService.executeAsyncTask(i);
        }


    }





}
